<html>
<head><meta charset="utf-8"><title>Cast-to-raw without reborrow · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html">Cast-to-raw without reborrow</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="163535069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535069">(Apr 17 2019 at 06:26)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> Is there any way to turn a <code>&amp;mut</code> into a <code>*mut</code> without incurring a reborrow or an intermediate assignment? I am rewriting parts of Stacked Borrows, also to hopefully fix the problems you ran into when implementing the "take a raw ref" operator, but sometimes it is just impossible to even generate the MIR that I'd like to test.</p>



<a name="163535183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535183">(Apr 17 2019 at 06:29)</a>:</h4>
<p>I don't think so, the way that we generate the cast means that there has to be a reborrow.</p>



<a name="163535419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535419">(Apr 17 2019 at 06:34)</a>:</h4>
<p>Dang. Well I guess that means we'll have to be creative when that is finally possible, and write the necessary tests then. Would be much easier now when everything is still fresh^^</p>



<a name="163535839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535839">(Apr 17 2019 at 06:44)</a>:</h4>
<p>I don't know exactly the details, but i heard that it is defined behavior to first wrap the &amp;mut with <code>Some</code> then transmute it to a <code>*mut</code>. Does that involve a reborrow or an intermediate assignment?</p>



<a name="163535940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535940">(Apr 17 2019 at 06:46)</a>:</h4>
<p>the transmute unfortunately does not have all the effects of a cast</p>



<a name="163535956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535956">(Apr 17 2019 at 06:47)</a>:</h4>
<p>and it is the cast that I wanted to study here</p>



<a name="163535959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163535959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163535959">(Apr 17 2019 at 06:47)</a>:</h4>
<p>(also, no need to wrap it in <code>Some</code>, you can just transmute <code>&amp;mut</code> to <code>*mut</code> -- but a cast is pretty much always preferred)</p>



<a name="163536042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw%20without%20reborrow/near/163536042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Cast-to-raw.20without.20reborrow.html#163536042">(Apr 17 2019 at 06:49)</a>:</h4>
<p>thanks</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>